package de.hfu.android;

import android.content.SharedPreferences;
import android.os.Bundle;
import android.preference.CheckBoxPreference;
import android.preference.ListPreference;
import android.preference.Preference;
import android.preference.Preference.OnPreferenceChangeListener;
import android.preference.PreferenceManager;
import android.preference.Preference.OnPreferenceClickListener;
import android.preference.PreferenceActivity;

public class SettingActivity extends PreferenceActivity {

	@Override
	protected void onCreate(Bundle savedInstanceState) {
		super.onCreate(savedInstanceState);
		addPreferencesFromResource(R.xml.preferences);

		final ListPreference lsLocation = (ListPreference) findPreference("campus_location_pref");
		final SharedPreferences prefs = PreferenceManager
				.getDefaultSharedPreferences(this);

		lsLocation
				.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

					@Override
					public boolean onPreferenceChange(Preference preference,
							Object newValue) {
						String campus = (String) newValue;
						SharedPreferences.Editor editor = prefs.edit();
						editor.putString("campus", campus);
						editor.putBoolean("changedInternet",
								!campus.equalsIgnoreCase(lsLocation.getValue()));
						editor.commit();				
						return true;
					}
				});

		final ListPreference lsLanguage = (ListPreference) findPreference("dish_language");
		lsLanguage
				.setOnPreferenceChangeListener(new OnPreferenceChangeListener() {

					@Override
					public boolean onPreferenceChange(Preference preference,
							Object newValue) {
						String language = (String) newValue;
						SharedPreferences.Editor editor = prefs.edit();						
						editor.putBoolean("changedLocal",
								!language.equalsIgnoreCase(lsLanguage.getValue()));
						editor.commit();
						return true;
					}
				});
	}

	static String chooseCampus() {

		return null;
	}
}
